/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gw.reportbuilder;

import gw.reportbuilder.Report.Builder;
import gw.reportbuilder.column.Column;
import gw.reportbuilder.filter.Filter;
import gw.reportbuilder.filter.Operator;
import gw.reportbuilder.table.Table;
import gw.reportbuilder.util.TableMetadata;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Sostenes
 */
public class ReportBO {

    public ReportBO() {
    }

    public List<Table> getViewList() throws Exception {

        return TableMetadata.INSTANCE.getTableList();
    }

    public List<Column> getColumns(String viewName) throws Exception {

        return TableMetadata.INSTANCE.getColumnList(viewName);
    }

    public List<Operator> getOperators(String viewName, String columnName, String columnType) throws Exception {

        return TableMetadata.INSTANCE.getOperators(viewName, columnName, columnType);
    }

    public List<String> getColumnValues(String viewName, String columnName) throws Exception {

        ReportDAO dao = new ReportDAO();

        return dao.getColumnValues(viewName, columnName);
    }

    public Collection<Object[]> getReportResult(Report report) throws Exception {

        ReportDAO dao = new ReportDAO();

        return dao.getReportResult(report);

    }

    public void saveReport(Report report) throws Exception {

        ReportDAO dao = new ReportDAO();
        dao.insertReport(report);
    }

    public Report getReport(String reportTitle, Table table, List<Column> columns, List<Filter> filters) {

        Builder builder = new Report.Builder(reportTitle, table);

        for (Column column : columns) {

            builder.addColumn(column);
        }

        for (Filter filter : filters) {

            builder.addFilter(filter);
        }

        Report report = builder.build();

        return report;
    }
    
    public Map<Integer, String> listReports() throws Exception {
        
        ReportDAO dao = new ReportDAO();
        
        return dao.listReports();
    }
    
    public Report getReport(int id) throws Exception {
        
        ReportDAO dao = new ReportDAO();
        
        return dao.getReport(id);
    }
    
    public void deleteReport(int id) throws Exception {
        
        ReportDAO dao = new ReportDAO();
        
        dao.deleteReport(id);
    }
    
    public boolean checkReportExists(String reportTitle) throws Exception {
        
        ReportDAO dao = new ReportDAO();
        
        return dao.checkReportExists(reportTitle);
    }
}
